package com.codingman.springmvcdemo3;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class EmployeeController {
	@RequestMapping("/display1")
	public String displayForm1(Model model) {
		return "index1";
	}

	@RequestMapping("/show")
	public String submitForm(@ModelAttribute("employee") Employee res) {
		return "show1";
	}

	@ModelAttribute("sexList")
	public Map<String, String> getSexList() {
		Map<String, String> sexList = new HashMap<String, String>();
		sexList.put("F", "Female");
		sexList.put("M", "Male");
		return sexList;
	}
	
	@ModelAttribute("countryList")
	public List<String> getCountryList() {
		List<String> countryList = new ArrayList<String>();
		countryList.add("USA");
		countryList.add("China");
		countryList.add("England");
		return countryList;
	}
	
	@RequestMapping("/display2")
	public String displayForm2(Model model) {
		Employee emp = new Employee();
		model.addAttribute("employee", emp);
		return "index2";
	}
}
